package mse.eai.jbpm.registerBetProcess;

import org.hibernate.StaleObjectStateException;
import org.jboss.logging.Logger;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

public class HandleAccountMovementResult implements ActionHandler {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5906789266444888848L;
	private static final Logger log = Logger
			.getLogger(HandleAccountMovementResult.class);

	public void execute(ExecutionContext context) throws Exception {
		
		log.info("Executing ---------->");
		
		try {
			String result = (String)context.getVariable("accountMovementResult");
			
			log.info("Got from context: " + "accountMovementResult  = " + context.getVariable("accountMovementResult"));
			
			if (!result.equals("OK")) {
				// TODO : What to do????	
				log.info("ACCOUNT MOVEMENT WAS NOT OK, SUSPENDING THE PROCESS");
				context.getProcessInstance().suspend();
				return;
			}
			context.leaveNode();

		} catch (Exception ex) {
			log.error("Exception: ", ex);
			log.error("ProcessInstance will be suspended");
			context.getProcessInstance().suspend();
		}

		log.info("<--------------- Done");
	}

}